package com.java.netty.nio.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
 * @Author: Dgg
 * @Date: 2021/12/26 23:23
 */
public class NettyByteBuf02 {

	public static void main(String[] args) throws UnsupportedEncodingException {
		ByteBuf byteBuf = Unpooled.copiedBuffer("hello World!", Charset.forName("utf-8"));


		if (byteBuf.hasArray()) {
			byte[] array = byteBuf.array();

			//将array 转换成字符串
			System.out.println(new String(array, "utf-8"));

			System.out.println(byteBuf.arrayOffset());
			System.out.println(byteBuf.readerIndex());
			System.out.println(byteBuf.writerIndex());
			System.out.println(byteBuf.capacity());

			int i = byteBuf.readableBytes();

			System.out.println("len=" + i);
		}
	}
}
